﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;

namespace MyVocationSpace
{
    public partial class SearchMemberList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            BAL.conn.connectionString = ConfigurationManager.ConnectionStrings["connectionstring"].ConnectionString;
            if (!IsPostBack)
            {
                if (Request.QueryString["Industry"] != null && Request.QueryString["Industry"] != "") 
                {
                    string strIndustry = Request.QueryString["Industry"].ToString();
                    ViewState["strIndustry"] = strIndustry;
                    if (Request.QueryString["Industry"] != "")
                    {
                        string strIndus = BAL.Vocation.GetIndustryDescriptionByIndusName(strIndustry);
                        lblDes.Text = strIndus;
                    }
                    
                    PopulateMymemberList(BAL.Vocation.GetPeapoleByIndustry(strIndustry));
                }

                if (Request.QueryString["Vocation"] != null && Request.QueryString["Vocation"] != "")
                {
                    string strVocation = Request.QueryString["Vocation"].ToString();
                    ViewState["strVocation"] = strVocation;
                    if (Request.QueryString["Vocation"] != "")
                    {
                        string strVoc = BAL.Vocation.GetVocationDescriptionByVocName(strVocation);
                        lblDes.Text = strVoc;
                    }

                    PopulateMymemberList(BAL.Vocation.GetPeapoleByVocation(strVocation));
                }

                //string strPeople = "";
                //if (Request.QueryString["strSearch"] != null)
                //{
                //    strPeople = Request.QueryString["strSearch"].ToString();
                //    ViewState["strPeople"] = strPeople;
                //    PopulateMymemberList(BAL.Users.GetPeopleByName(strPeople, Convert.ToInt32(Session["UserID"])));
                //}
                //else
                //{
                //    ViewState["strPeople"] = "";
                //}
            }

           // PopulateMymemberList(BAL.Users.GetPeopleByName(ViewState["strPeople"].ToString(), Convert.ToInt32(Session["UserID"])));


        }
        public void PopulateMymemberList(DataSet ds)
        {

            if (ds.Tables.Count > 0)
            {
                if (ds.Tables[0].Rows.Count > 0)
                {

                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        phMemebers.Controls.Add(new LiteralControl("<table class=\"light-border MemberList\"><tr><td align=\"Center\"   >"));
                        phMemebers.Controls.Add(new LiteralControl("<div style=\"float: left; padding: 2px;width:70px\"><a href=\"ViewProfile.aspx?IDUser=" + dr["IDUser"] + "\">"));
                        if (!string.IsNullOrEmpty(dr["Photo"].ToString()))
                        {
                            phMemebers.Controls.Add(new LiteralControl("<img src=\"UsersPhoto/" + dr["Photo"].ToString() + "\" style=\"width: 60px; height: 60px;border: 0px\" alt=\"\" /></a>"));

                        }
                        else
                        {
                            phMemebers.Controls.Add(new LiteralControl("<img src=\"UsersPhoto/icon_no_photo_60x60.png\" style=\"width: 60px; height: 60px;border: 0px\" alt=\"\" /></a>"));
                        }
                        phMemebers.Controls.Add(new LiteralControl("</div>"));
                        //main
                        phMemebers.Controls.Add(new LiteralControl("<div style=\"float: left; width: 345px;text-align:left\">"));
                        //for name
                        phMemebers.Controls.Add(new LiteralControl("<div  id=\"membername\" ><a href=\"ViewProfile.aspx?IDUser=" + dr["IDUser"].ToString() + "\" >" + dr["Firstname"].ToString() + " " + dr["Lastname"].ToString() + "</a></div>"));
                        //for position
                       // phMemebers.Controls.Add(new LiteralControl("<div class=\"medium-msg-black\"> " + dr["CurrentPosition"].ToString() + "  at <span>" + dr["Orgnization"].ToString() + "</span></div>"));
                        phMemebers.Controls.Add(new LiteralControl("<div class=\"medium-msg-black\"> " + dr["Designation"].ToString() + "</span></div>"));

                        //for country and industry
                        phMemebers.Controls.Add(new LiteralControl("<div class=\"medium-msg-light\">"));
                        phMemebers.Controls.Add(new LiteralControl("<span>" + dr["City"].ToString() + "</span>, <span><b>" + dr["CountryName"].ToString() + "</b></span>"));
                        phMemebers.Controls.Add(new LiteralControl("</div>"));
                        phMemebers.Controls.Add(new LiteralControl("<div>"));
                        phMemebers.Controls.Add(new LiteralControl("<span style=\"font-family:Arial;font-size:13px; font-weight:normal;color:#000;\">" + "Industry : " + "</span><span class=\"medium-msg-light\"><b>" + dr["IndustryName"].ToString() + "</b></span>"));
                        phMemebers.Controls.Add(new LiteralControl("</div>"));
                        phMemebers.Controls.Add(new LiteralControl("</div>"));


                        //connections
                        phMemebers.Controls.Add(new LiteralControl("<div style=\"float:left; width:100px;\">"));

                        //Button btnView = new Button();
                        //btnView.ID = dr["IDUser"].ToString();
                        //btnView.CommandArgument = dr["IDUser"].ToString();
                        //btnView.ToolTip = "View" + " " + dr["Firstname"].ToString() + "'s Profile";
                        //btnView.Text = "View Profile";
                        //btnView.CssClass = "formBtnEdit";

                        ////btnView.Click += new EventHandler(bntView_Click);

                        //btnView.OnClientClick = "viewProfile(" + dr["IDUser"].ToString() +");";

                        //phMemebers.Controls.Add(btnView);

                        phMemebers.Controls.Add(new LiteralControl("<a class=\"formBtnProfie\" style=\"padding:2px; backgound-color:#1C6F93; height:28px; color:white;\" href=\"ViewProfile.aspx?IDUser=" + dr["IDUser"].ToString() + "\" > View Profile </a>"));
                        phMemebers.Controls.Add(new LiteralControl("</div>"));

                        //main end
                        phMemebers.Controls.Add(new LiteralControl("</td></tr></table>"));
                    }

                }
                else
                {
                    phMemebers.Controls.Add(new LiteralControl("<table><tr><td style=\"color:Red;font-weight:bold;font-size: 13px;font-family:Verdana;\">Data Not Found...!!!</td></tr></table>"));

                }
            }

        }

        //protected void bntView_Click(object sender, EventArgs e)
        //{
        //    Button lnkView = (Button)sender;
        //    int IdUser = Convert.ToInt32(lnkView.CommandArgument);
        //    Response.Redirect("ViewProfile.aspx?IDUser=" + IdUser + "");
        //}
    }
}